package com.jm.common.conf.mybatis;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

public class EnhanceDelete extends AbstractMethod {
    public EnhanceDelete() {
        this("enhanceDelete");

    }

    public EnhanceDelete(String methodName) {
        super(methodName);
    }

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
//        final String sql = "<script>delete from " + tableInfo.getTableName() + " where " + tableInfo.getKeyColumn() + "=#{id} limit 1</script>";
        final String sql = "<script>update " + tableInfo.getTableName() + " set deleted=1 where deleted=0 and " + tableInfo.getKeyColumn() + "=#{id}  limit 1</script>";
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        final String id = "enhanceDelete";
        return this.addDeleteMappedStatement(mapperClass, id, sqlSource);
    }

}
